  //***********************************************************//
 //             学生程序                                      //
//***********************************************************//
//学生权限：查看教师、学生信息
//***********************************************************//

#include"my.h"

void student_search_student_byclass(T_LINK *head_teacher,S_LINK *head_student)
{

    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t******          学生－查看班级所有学生       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t                     当前用户：%s                    \n",user_name);
    printf("\t\t\t                                                      \n");

    int searchclass;
    printf("\n\n\t\t\t\t请输入要查询的班级: ");
    scanf("%d",&searchclass);

    getchar();

    S_LINK *p;
    p=head_student->next;
    printf("\n\t\t\t\t\t%d班所有学生列表\n\n",searchclass);
    printf("\t\t\t姓名\t\t学号\t年龄\tC语言\t英语\t数学\t排名\n");

    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {

	if(p->class==searchclass)
	{
	    printf("\t\t\t%-16s",p->name);
	    printf("%2d",p->ID);
	    printf("%8d",p->age);
	    printf("%8d",p->c_score);
	    printf("%8d",p->english_score);
	    printf("%8d",p->math_score);
	    printf("%8d\n",p->line_num);
	}
	p=p->next;
    }

    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    student_look_student_info(head_teacher,head_student);

}//end search_student_byclass


//查看学生帐户函数里的函数
void student_search_student_byID(T_LINK *head_teacher,S_LINK *head_student)
{
    int search_studentID;
    printf("\t\t\t搜索学生学号:");
    scanf("%d",&search_studentID);

    getchar();

    S_LINK *p;
    p=head_student->next;


    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {

	if(search_studentID==p->ID)//匹配成功进入
	{
	    printf("\n\t\t\t学号为%d 的学生信息如下:",search_studentID);
	    printf("\n\t\t\t姓 名: %s",p->name);
	    printf("\n\t\t\t年 龄: %d",p->age);
	    printf("\n\t\t\t班 级: %d",p->class);
	    printf("\n\t\t\t排 名: %d",p->line_num);
	    printf("\n\t\t\tC成绩: %d",p->c_score);
	    printf("\n\t\t\t英语成绩: %d",p->english_score);
	    printf("\n\t\t\t数学成绩: %d",p->math_score);

	    break;
	}
	p=p->next;
    }
    if(p==NULL)
    {
	printf("\t\t\t找不到该学号的学生 !\n");		
    }

    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    student_look_student_info(head_teacher,head_student);
}


void student_search_student_byname(T_LINK *head_teacher,S_LINK *head_student)
{
	char search_student_Name[16];
	printf("\t\t\t搜索学生姓名:");
    	scanf("%s",search_student_Name);
 

	S_LINK *p;
	p=head_student->next;

	while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{

		if(0==strcmp(search_student_Name,p->name))//匹配成功进入
		{
			printf("\n\t\t\t姓名为%s 的学生信息如下:",search_student_Name);
			printf("\n\t\t\t学 号: %d",p->ID);
			printf("\n\t\t\t年 龄: %d",p->age);
			printf("\n\t\t\t班 级: %d",p->class);
			printf("\n\t\t\t排 名: %d",p->line_num);
			printf("\n\t\t\tC成绩: %d",p->c_score);
			printf("\n\t\t\t英语成绩: %d",p->english_score);
			printf("\n\t\t\t数学成绩: %d",p->math_score);


			break;
		}
		p=p->next;
	}
	if(p==NULL)
	{
	    printf("\t\t\t找不到该姓名的学生 !\n");

	}

	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	student_look_student_info(head_teacher,head_student);
}

//查看学生帐户函数里的函数
void student_look_list_teacher(T_LINK *head_teacher,S_LINK *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t******          学生－查看教师列表           *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t                     当前用户：%s                    \n",user_name);
    printf("\t\t\t                                                      \n");

    T_LINK *p;
    p=head_teacher->next;
    int flag_scan_check_user=1;//结构体位置

    printf("\t\t\t\t\t所有教师列表\n\n");
    printf("\t\t\t姓名\t\t年龄\t序号\t班级\t职 称\t\t任 教\n");

    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {
	printf("\t\t%d    %-16s",flag_scan_check_user++,p->name);
	printf("%6d",p->age);
	printf("%8d",p->ID);
	printf("%8d",p->class);
	printf("\t%-16s",p->duty);
	printf("\t%s\n",p->teaching);

	p=p->next;
    }


    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    student_look_teacher_info(head_teacher,head_student);

}

void student_search_teacher_byID(T_LINK *head_teacher,S_LINK *head_student)
{

    int search_teacherID;
    printf("\t\t\t搜索教师序号:");
    scanf("%d",&search_teacherID);

    getchar();
    T_LINK *p;
    p=head_teacher->next;

    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {
	if(search_teacherID==p->ID)//匹配成功进入
	{
	    printf("\n\t\t\t序号为%d的教师信息如下:",search_teacherID);
	    printf("\n\t\t\t姓 名: %s",p->name);
	    printf("\n\t\t\t年 龄: %d",p->age);
	    printf("\n\t\t\t班 级: %d",p->class);
	    printf("\n\t\t\t职 称: %s",p->duty);
	    printf("\n\t\t\t任 教: %s",p->teaching);

	    break;
	}
	p=p->next;
    }
    if(p==NULL)
    {
	printf("\t\t\t找不到该序号的教师 !\n");
    }

    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    student_look_teacher_info(head_teacher,head_student);

}

void student_search_teacher_byname(T_LINK *head_teacher,S_LINK *head_student)
{
    char search_teacher_Name[16];
    printf("\t\t\t搜索教师姓名:");
    scanf("%s",search_teacher_Name);


    T_LINK *p;
    p=head_teacher->next;

    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {
	if(0==strcmp(search_teacher_Name,p->name))//匹配成功进入
	{
	    printf("\n\t\t\t姓名为%s 的教师信息如下:",search_teacher_Name);
	    printf("\n\t\t\t序 号: %d",p->ID);
	    printf("\n\t\t\t年 龄: %d",p->age);
	    printf("\n\t\t\t班 级: %d",p->class);
	    printf("\n\t\t\t职 称: %s",p->duty);
	    printf("\n\t\t\t任 教: %s",p->teaching);

	    break;
	}
	p=p->next;
    }
    if(p==NULL)
    {
	printf("\t\t\t找不到该姓名的教师 !\n");		
    }

    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    student_look_teacher_info(head_teacher,head_student);

}

/***查看帐户信息函数里的函数***/
void student_look_teacher_info(T_LINK *head_teacher,S_LINK *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             学生－查看教师帐户       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择：1.查看教师列表                  \n");
    printf("\t\t\t                      2.按工号搜索教师                \n");
    printf("\t\t\t                      3.按姓名搜索教师                \n");
    printf("\t\t\t                      4.返回上一级菜单                \n");

    int flag_student_home_1_3_chose=1;
    while(flag_student_home_1_3_chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");

	int student_home_1_3_chose;
	scanf("%d",&student_home_1_3_chose);

	getchar();
	flag_student_home_1_3_chose=0;
	switch (student_home_1_3_chose)
	{
	    case 1:student_look_list_teacher(head_teacher,head_student);break;
	    case 2:student_search_teacher_byID(head_teacher,head_student);break;
	    case 3:student_search_teacher_byname(head_teacher,head_student);break;
	    case 4:student_look_user_info(head_teacher,head_student);break;
	    default :flag_student_home_1_3_chose=1;
		     printf("\t\t\t选择错误，请重新输入!\n");
	}
    }

}


void student_look_student_info(T_LINK *head_teacher,S_LINK *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             学生－查看学生帐户       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择：1.查看学生列表                  \n");
    printf("\t\t\t                      2.按学号搜索学生                \n");
    printf("\t\t\t                      3.按姓名搜索学生                \n");
    printf("\t\t\t                      4.按班级搜索学生                \n");
    printf("\t\t\t                      5.返回上一级菜单                \n");

    int flag_student_home_1_3_chose=1;
    while(flag_student_home_1_3_chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");

	int student_home_1_3_chose;
	scanf("%d",&student_home_1_3_chose);

	getchar();
	flag_student_home_1_3_chose=0;
	switch (student_home_1_3_chose)
	{
	    case 1:student_look_list_student(head_teacher,head_student);break;
	    case 2:student_search_student_byID(head_teacher,head_student);break;
	    case 3:student_search_student_byname(head_teacher,head_student);break;
	    case 4:student_search_student_byclass(head_teacher,head_student);break;
	    case 5:student_look_user_info(head_teacher,head_student);break;
	    default :flag_student_home_1_3_chose=1;
		     printf("\t\t\t选择错误，请重新输入!\n");
	}
    }

}

void student_look_list_student(T_LINK *head_teacher,S_LINK *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t******          学生－查看学生列表           *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t                     当前用户：%s                    \n",user_name);
    printf("\t\t\t                                                      \n");
    printf("\t\t\t              请选择 1.按学号顺序显示                 \n");
    printf("\t\t\t                     2.按名次顺序显示                 \n");
    printf("\t\t\t                     3.按学科成绩显示                 \n");
    printf("\t\t\t                     4.查看默认学生列表                 \n");
    printf("\t\t\t                     5.返回上一级菜单                  \n");
    printf("\t\t\t                                                      \n");
    printf("\t\t\t                                                      \n");
    printf("\n\t\t\t");

    int flag_look_student_by;

    scanf("%d",&flag_look_student_by);

    getchar();

    if(flag_look_student_by==1)
    {
	S_LINK *head=NULL;
	S_LINK *p;
	S_LINK *p_new;
	S_LINK *head_sore=NULL;
	S_LINK *tmp_p;
	S_LINK *max_p;
	S_LINK *p_sore;
	S_LINK *free_p;

	copy_student_link(head_student,&head);
	head_sore=malloc(sizeof(S_LINK));
	memset(head_sore,0,sizeof(S_LINK));

	p=head;
	p_sore=head_sore;

	//****************************以下程序将输出递减排序*******************************//

	while(head->next)
	{
	    p=head->next;

	    max_p=malloc(sizeof(S_LINK));
	    memset(max_p,0,sizeof(S_LINK));

	    max_p->ID=-1;

	    while(p)
	    {
		if(p->ID>max_p->ID)
		{
		    max_p->ID=p->ID;
		    strcpy( max_p->name,p->name);
		    max_p->math_score=p->math_score;
		    max_p->english_score=p->english_score;
		    max_p->line_num=p->line_num;
		    max_p->c_score=p->c_score;
		    max_p->class=p->class;
		    max_p->age=p->age;
		    strcpy(max_p->pass_word,p->pass_word);

		}

		p=p->next;
	    }

	    free_p=head;
	    tmp_p=head;

	    while(free_p->next)
	    {
		if(max_p->ID==free_p->ID)
		{
		    break;
		}
		tmp_p=free_p;
		free_p=free_p->next;

	    }


	    if(free_p==head)
	    {
		if(free_p->next)
		{
		    head=free_p->next;
		    free_p->next->pre=head;
		}
		else
		{
		    head=NULL;
		}
	    }
	    else
	    {
		if(free_p->next)
		{
		    tmp_p->next=free_p->next;
		    free_p->next->pre=tmp_p;
		}
		else
		{
		    tmp_p->next=NULL;
		}
	    }

	    free(free_p);

	    if(p_sore==NULL)
	    {
		max_p->next=NULL;
		max_p->pre=NULL;
		p_sore=max_p;
	    }					
	    else
	    {
		max_p->next=p_sore->next;
		max_p->pre=p_sore;
		p_sore->next=max_p;
	    }				
	    p_sore=p_sore->next;					
	}
	//**********************************递减结束***************************************//
	//******************以下程序将输出按递增排序****************************//

	p=head;
	while(head_sore->next)
	{
	    tmp_p=head_sore;
	    free_p=head_sore->next;

	    p_new=malloc(sizeof(S_LINK));
	    memset(p_new,0,sizeof(S_LINK));
	    while(1)
	    {
		if(free_p->next==NULL)
		{
		    p_new->ID=free_p->ID;
		    strcpy( p_new->name,free_p->name);
		    p_new->math_score=free_p->math_score;
		    p_new->english_score=free_p->english_score;
		    p_new->line_num=free_p->line_num;
		    p_new->c_score=free_p->c_score;
		    p_new->class=free_p->class;
		    p_new->age=free_p->age;
		    strcpy(p_new->pass_word,free_p->pass_word);

		    if(p==NULL)
		    {
			p_new->next=NULL;
			p_new->pre=NULL;
			p=p_new;
		    }					
		    else
		    {
			p_new->next=p->next;
			p_new->pre=p;
			p->next=p_new;
		    }

		    tmp_p->next=free_p->next;
		    free(free_p);
		    break;

		}
		tmp_p=tmp_p->next;
		free_p=free_p->next;

	    }
	    p=p->next;
	}

	//***********************************递增排序结束**********************************************//

	system("clear");
	printf("\n\n\t\t\t\t\t按学号显示学生列表\n\n");
	printf("\t\t\t学号\t姓名\t\t年龄\tC语言\t英语\t数学\t排名\n");

	p=head->next;
	while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{
	    printf("\t\t\t%2d",p->ID);
	    printf("\t%-16s",p->name);
	    printf("%2d",p->age);
	    printf("%8d",p->c_score);
	    printf("%8d",p->english_score);
	    printf("%8d",p->math_score);
	    printf("%8d\n",p->line_num);
	    p=p->next;
	}

	free_student_link(&head);
	free_student_link(&head_sore);

	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	student_look_list_student(head_teacher,head_student);
    }//end flag_look_student_by==1

    if(flag_look_student_by==2)
    {
	S_LINK *head=NULL;
	S_LINK *p;
	S_LINK *p_new;
	S_LINK *head_sore=NULL;
	S_LINK *tmp_p;
	S_LINK *max_p;
	S_LINK *p_sore;
	S_LINK *free_p;

	copy_student_link(head_student,&head);
	head_sore=malloc(sizeof(S_LINK));
	memset(head_sore,0,sizeof(S_LINK));

	p=head;
	p_sore=head_sore;


	//****************************以下程序将输出递减排序*******************************//

	while(head->next)
	{
	    p=head->next;

	    max_p=malloc(sizeof(S_LINK));
	    memset(max_p,0,sizeof(S_LINK));

	    max_p->line_num=-1;

	    while(p)
	    {
		if(p->line_num>max_p->line_num)
		{
		    max_p->ID=p->ID;
		    strcpy( max_p->name,p->name);
		    max_p->math_score=p->math_score;
		    max_p->english_score=p->english_score;
		    max_p->line_num=p->line_num;
		    max_p->c_score=p->c_score;
		    max_p->class=p->class;
		    max_p->age=p->age;
		    strcpy(max_p->pass_word,p->pass_word);

		}

		p=p->next;
	    }

	    free_p=head;
	    tmp_p=head;

	    while(free_p->next)
	    {
		if(max_p->line_num==free_p->line_num)
		{
		    break;
		}
		tmp_p=free_p;
		free_p=free_p->next;

	    }


	    if(free_p==head)
	    {
		if(free_p->next)
		{
		    head=free_p->next;
		    free_p->next->pre=head;
		}
		else
		{
		    head=NULL;
		}
	    }
	    else
	    {
		if(free_p->next)
		{
		    tmp_p->next=free_p->next;
		    free_p->next->pre=tmp_p;
		}
		else
		{
		    tmp_p->next=NULL;
		}
	    }

	    free(free_p);

	    if(p_sore==NULL)
	    {
		max_p->next=NULL;
		max_p->pre=NULL;
		p_sore=max_p;
	    }					
	    else
	    {
		max_p->next=p_sore->next;
		max_p->pre=p_sore;
		p_sore->next=max_p;
	    }				
	    p_sore=p_sore->next;					
	}



	//**********************************递减结束***************************************//


	//******************以下程序将输出按递增排序****************************//

	p=head;
	while(head_sore->next)
	{
	    tmp_p=head_sore;
	    free_p=head_sore->next;

	    p_new=malloc(sizeof(S_LINK));
	    memset(p_new,0,sizeof(S_LINK));
	    while(1)
	    {
		if(free_p->next==NULL)
		{
		    p_new->ID=free_p->ID;
		    strcpy( p_new->name,free_p->name);
		    p_new->math_score=free_p->math_score;
		    p_new->english_score=free_p->english_score;
		    p_new->line_num=free_p->line_num;
		    p_new->c_score=free_p->c_score;
		    p_new->class=free_p->class;
		    p_new->age=free_p->age;
		    strcpy(p_new->pass_word,free_p->pass_word);

		    if(p==NULL)
		    {
			p_new->next=NULL;
			p_new->pre=NULL;
			p=p_new;
		    }					
		    else
		    {
			p_new->next=p->next;
			p_new->pre=p;
			p->next=p_new;
		    }

		    tmp_p->next=free_p->next;
		    free(free_p);
		    break;

		}
		tmp_p=tmp_p->next;
		free_p=free_p->next;

	    }
	    p=p->next;
	}

	//***********************************递增排序结束**********************************************//

	system("clear");
	printf("\n\n\t\t\t\t\t按名次显示学生列表\n\n");
	printf("\t\t\t排名\t姓名\t\t学号\t年龄\tC语言\t英语\t数学\n");

	p=head->next;
	while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{
	    printf("\t\t\t%2d",p->line_num);
	    printf("\t%-16s",p->name);
	    printf("%2d",p->ID);
	    printf("%8d",p->age);
	    printf("%8d",p->c_score);
	    printf("%8d",p->english_score);
	    printf("%8d\n",p->math_score);
	    p=p->next;
	}


	free_student_link(&head);
	free_student_link(&head_sore);
	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	student_look_list_student(head_teacher,head_student);
    }//end flag_look_student_by==2

    if(flag_look_student_by==3)
    {
	system("clear");
	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t******        学生－按学科成绩显示学生列表     *******\n");
	printf("\t\t\t******************************************************\n");
	printf("\t\t\t                     当前用户：%s                    \n",user_name);
	printf("\t\t\t                                                      \n");
	printf("\t\t\t              请选择 1.按C语言成绩顺序显示                 \n");
	printf("\t\t\t                     2.按英语成绩顺序显示                 \n");
	printf("\t\t\t                     3.按数学成绩顺序显示                 \n");
	printf("\t\t\t                     4.返回上一级菜单                  \n");
	printf("\t\t\t                                                      \n");
	printf("\t\t\t                                                      \n");
	printf("\n\t\t\t");

	int flag_look_student_by_subject_score;

	scanf("%d",&flag_look_student_by_subject_score);

	getchar();
	if(flag_look_student_by_subject_score==1)
	{
	    S_LINK *head=NULL;
	    S_LINK *p;
	    S_LINK *head_sore=NULL;
	    S_LINK *tmp_p;
	    S_LINK *max_p;
	    S_LINK *p_sore;
	    S_LINK *free_p;


	    copy_student_link(head_student,&head);

	    head_sore=malloc(sizeof(S_LINK));
	    memset(head_sore,0,sizeof(S_LINK));

	    p=head;
	    p_sore=head_sore;


	    //****************************以下程序将输出递减排序*******************************//

	    while(head->next)
	    {
		p=head->next;

		max_p=malloc(sizeof(S_LINK));
		memset(max_p,0,sizeof(S_LINK));

		max_p->c_score=-1;

		while(p)
		{
		    if(p->c_score>max_p->c_score)
		    {
			max_p->ID=p->ID;
			strcpy( max_p->name,p->name);
			max_p->math_score=p->math_score;
			max_p->english_score=p->english_score;
			max_p->line_num=p->line_num;
			max_p->c_score=p->c_score;
			max_p->class=p->class;
			max_p->age=p->age;
			strcpy(max_p->pass_word,p->pass_word);

		    }

		    p=p->next;
		}

		free_p=head;
		tmp_p=head;

		while(free_p->next)
		{
		    if(max_p->c_score==free_p->c_score)
		    {
			break;
		    }
		    tmp_p=free_p;
		    free_p=free_p->next;

		}


		if(free_p==head)
		{
		    if(free_p->next)
		    {
			head=free_p->next;
			free_p->next->pre=head;
		    }
		    else
		    {
			head=NULL;
		    }
		}
		else
		{
		    if(free_p->next)
		    {
			tmp_p->next=free_p->next;
			free_p->next->pre=tmp_p;
		    }
		    else
		    {
			tmp_p->next=NULL;
		    }
		}

		free(free_p);

		if(p_sore==NULL)
		{
		    max_p->next=NULL;
		    max_p->pre=NULL;
		    p_sore=max_p;
		}					
		else
		{
		    max_p->next=p_sore->next;
		    max_p->pre=p_sore;
		    p_sore->next=max_p;
		}				
		p_sore=p_sore->next;					
	    }

	    //**********************************递减结束***************************************//

	    system("clear");
	    printf("\n\n\t\t\t\t\t按C语言成绩显示学生列表 (由高到低)\n\n");
	    printf("\t\t\t学号\t姓名\t\t年龄\tC语言\t英语\t数学\t排名\n");

	    int averc_score=0;
	    int flag_count=0;
	    p=head_sore->next;
	    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	    {
		printf("\t\t\t%2d",p->ID);
		printf("\t%-16s",p->name);
		printf("%2d",p->age);
		printf("%8d",p->c_score);
		printf("%8d",p->english_score);
		printf("%8d",p->math_score);
		printf("%8d\n",p->line_num);

		averc_score=averc_score+(p->c_score);
		flag_count++;

		p=p->next;
	    }

	    printf("\n\t\t\tC语言成绩平均分为：%.2f\n\n",(float)averc_score/flag_count);


	    free_student_link(&head);
	    free_student_link(&head_sore);

	    printf("\n\n\t\t\t******************************************************\n");
	    printf("\t\t\t                按回车键返回上一级菜单                \n");
	    printf("\t\t\t******************************************************\n");
	    getchar();
	    getchar();
	    student_look_list_student(head_teacher,head_student);



	}//end c_score
	if(flag_look_student_by_subject_score==2)
	{
	    S_LINK *head=NULL;
	    S_LINK *p;
	    S_LINK *head_sore=NULL;
	    S_LINK *tmp_p;
	    S_LINK *max_p;
	    S_LINK *p_sore;
	    S_LINK *free_p;

	    copy_student_link(head_student,&head);

	    head_sore=malloc(sizeof(S_LINK));
	    memset(head_sore,0,sizeof(S_LINK));

	    p=head;
	    p_sore=head_sore;


	    //****************************以下程序将输出递减排序*******************************//

	    while(head->next)
	    {
		p=head->next;

		max_p=malloc(sizeof(S_LINK));
		memset(max_p,0,sizeof(S_LINK));

		max_p->english_score=-1;

		while(p)
		{
		    if(p->english_score>max_p->english_score)
		    {
			max_p->ID=p->ID;
			strcpy( max_p->name,p->name);
			max_p->math_score=p->math_score;
			max_p->english_score=p->english_score;
			max_p->line_num=p->line_num;
			max_p->c_score=p->c_score;
			max_p->class=p->class;
			max_p->age=p->age;
			strcpy(max_p->pass_word,p->pass_word);

		    }

		    p=p->next;
		}

		free_p=head;
		tmp_p=head;

		while(free_p->next)
		{
		    if(max_p->english_score==free_p->english_score)
		    {
			break;
		    }
		    tmp_p=free_p;
		    free_p=free_p->next;

		}


		if(free_p==head)
		{
		    if(free_p->next)
		    {
			head=free_p->next;
			free_p->next->pre=head;
		    }
		    else
		    {
			head=NULL;
		    }
		}
		else
		{
		    if(free_p->next)
		    {
			tmp_p->next=free_p->next;
			free_p->next->pre=tmp_p;
		    }
		    else
		    {
			tmp_p->next=NULL;
		    }
		}

		free(free_p);

		if(p_sore==NULL)
		{
		    max_p->next=NULL;
		    max_p->pre=NULL;
		    p_sore=max_p;
		}					
		else
		{
		    max_p->next=p_sore->next;
		    max_p->pre=p_sore;
		    p_sore->next=max_p;
		}				
		p_sore=p_sore->next;					
	    }

	    //**********************************递减结束***************************************//

	    system("clear");
	    printf("\n\n\t\t\t\t\t按英语成绩显示学生列表 (由高到低)\n\n");
	    printf("\t\t\t学号\t姓名\t\t年龄\tC语言\t英语\t数学\t排名\n");

	    int averenglish_score=0;
	    int flag_count=0;
	    p=head_sore->next;
	    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	    {
		printf("\t\t\t%2d",p->ID);
		printf("\t%-16s",p->name);
		printf("%2d",p->age);
		printf("%8d",p->c_score);
		printf("%8d",p->english_score);
		printf("%8d",p->math_score);
		printf("%8d\n",p->line_num);

		averenglish_score=averenglish_score+(p->english_score);
		flag_count++;
		p=p->next;
	    }

	    printf("\n\t\t\t英语成绩平均分为：%.2f\n\n",(float)averenglish_score/flag_count);

	    free_student_link(&head);
	    free_student_link(&head_sore);

	    printf("\n\n\t\t\t******************************************************\n");
	    printf("\t\t\t                按回车键返回上一级菜单                \n");
	    printf("\t\t\t******************************************************\n");
	    getchar();
	    getchar();
	    student_look_list_student(head_teacher,head_student);


	}//end english_score

	if(flag_look_student_by_subject_score==3)
	{
	    S_LINK *head=NULL;
	    S_LINK *p;
	    S_LINK *head_sore=NULL;
	    S_LINK *tmp_p;
	    S_LINK *max_p;
	    S_LINK *p_sore;
	    S_LINK *free_p;


	    copy_student_link(head_student,&head);
	    head_sore=malloc(sizeof(S_LINK));
	    memset(head_sore,0,sizeof(S_LINK));

	    p=head;
	    p_sore=head_sore;
	    //****************************以下程序将输出递减排序*******************************//

	    while(head->next)
	    {
		p=head->next;

		max_p=malloc(sizeof(S_LINK));
		memset(max_p,0,sizeof(S_LINK));

		max_p->math_score=-1;

		while(p)
		{
		    if(p->math_score>max_p->math_score)
		    {
			max_p->ID=p->ID;
			strcpy( max_p->name,p->name);
			max_p->math_score=p->math_score;
			max_p->english_score=p->english_score;
			max_p->line_num=p->line_num;
			max_p->c_score=p->c_score;
			max_p->class=p->class;
			max_p->age=p->age;
			strcpy(max_p->pass_word,p->pass_word);

		    }

		    p=p->next;
		}

		free_p=head;
		tmp_p=head;

		while(free_p->next)
		{
		    if(max_p->math_score==free_p->math_score)
		    {
			break;
		    }
		    tmp_p=free_p;
		    free_p=free_p->next;

		}


		if(free_p==head)
		{
		    if(free_p->next)
		    {
			head=free_p->next;
			free_p->next->pre=head;
		    }
		    else
		    {
			head=NULL;
		    }
		}
		else
		{
		    if(free_p->next)
		    {
			tmp_p->next=free_p->next;
			free_p->next->pre=tmp_p;
		    }
		    else
		    {
			tmp_p->next=NULL;
		    }
		}

		free(free_p);

		if(p_sore==NULL)
		{
		    max_p->next=NULL;
		    max_p->pre=NULL;
		    p_sore=max_p;
		}					
		else
		{
		    max_p->next=p_sore->next;
		    max_p->pre=p_sore;
		    p_sore->next=max_p;
		}				
		p_sore=p_sore->next;					
	    }

	    //**********************************递减结束***************************************//

	    system("clear");
	    printf("\n\n\t\t\t\t\t按数学成绩显示学生列表 (由高到低)\n\n");
	    printf("\t\t\t学号\t姓名\t\t年龄\tC语言\t英语\t数学\t排名\n");

	    int avermath_score=0;
	    int flag_count=0;
	    p=head_sore->next;
	    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	    {
		printf("\t\t\t%2d",p->ID);
		printf("\t%-16s",p->name);
		printf("%2d",p->age);
		printf("%8d",p->c_score);
		printf("%8d",p->english_score);
		printf("%8d",p->math_score);
		printf("%8d\n",p->line_num);
		avermath_score=avermath_score+(p->math_score);
		flag_count++;
		p=p->next;
	    }
	    printf("\n\t\t\t数学成绩平均分为：%.2f\n\n",(float)avermath_score/flag_count);


	    free_student_link(&head);
	    free_student_link(&head_sore);

	    printf("\n\t\t\t******************************************************\n");
	    printf("\t\t\t                按回车键返回上一级菜单                \n");
	    printf("\t\t\t******************************************************\n");
	    getchar();
	    getchar();
	    student_look_list_student(head_teacher,head_student);


	}//end math_socre


	if(flag_look_student_by_subject_score==4)
	{
	    student_look_list_student(head_teacher,head_student);

	}

	if(flag_look_student_by_subject_score>4||flag_look_student_by_subject_score<1)
	{
	    printf("\t\t\t\t输入错误！按回车键返回上一级菜单\n\t\t\t\t ");
	    getchar();
	    getchar();
	    system("clear");
	    student_look_list_student(head_teacher,head_student);
	}
    }//end flag_look_student_by==3

    if(flag_look_student_by==4)
    {

	system("clear");
	printf("\n\n\t\t\t\t\t所有学生列表\n");
	printf("\t\t\t姓名\t\t学号\t年龄\tC成绩\t英语\t数学\t排名\n");

	S_LINK *p;
	p=head_student->next;
	while(p)
	{
	    printf("\t\t\t%-16s",p->name);
	    printf("%2d",p->ID);
	    printf("%8d",p->age);
	    printf("%8d",p->c_score);
	    printf("%8d",p->english_score);
	    printf("%8d",p->math_score);
	    printf("%8d\n",p->line_num);

	    p=p->next;
	}

	printf("\n\n\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	student_look_list_student(head_teacher,head_student);

    }

    if(flag_look_student_by==5)
    {
	student_look_student_info(head_teacher,head_student);
    }

    if(flag_look_student_by>5||flag_look_student_by<1)
    {
	printf("\t\t\t\t输入错误！按回车键返回上一级菜单\n\t\t\t\t ");
	getchar();
	getchar();
	system("clear");
	student_look_student_info(head_teacher,head_student);
    }
}

void manage_my_info(T_LINK **head_teacher,S_LINK **head_student)
{
    system("clear");

    S_LINK *p;

    p=(*head_student);
    while(p)
    {
	if(0==strcmp(p->name,user_name))
	{
	    printf("\n\t\t\t\t您的帐户信息如下");
	    printf("\n\t\t\t姓名\t\t密码\t\t学号\t年龄\tC语言\t英语\t数学\t排名\n");

	    printf("\t\t\t%-16s",p->name);
	    printf("%-16s",p->pass_word);
	    printf("%2d",p->ID);
	    printf("%8d",p->age);
	    printf("%8d",p->c_score);
	    printf("%8d",p->english_score);
	    printf("%8d",p->math_score);
	    printf("%8d\n",p->line_num);

	    printf("\n\n\t\t\t只允许修改自己(%s)的密码、年龄\t\t\t\n\n",user_name);
	    printf("\t\t\t密码：");
	    scanf("%s",p->pass_word);
	    printf("\t\t\t年龄：");
	    scanf("%d",&p->age);

	    break;
	}
	p=p->next;

    }

    save_student_info(*head_student);
    printf("\n\n\n\t\t\t\t修改成功！\n\n");


    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();

    student_home(head_teacher,head_student);
}

void student_look_user_info(T_LINK *head_teacher,S_LINK *head_student)
{

    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             学生－查看帐户信息       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择：1.查看教师帐户                  \n");
    printf("\t\t\t                      2.查看学生帐户                  \n");
    printf("\t\t\t                      3.返回上一级菜单                \n");

    int flag_student_home_1_3_chose=1;
    while(flag_student_home_1_3_chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");

	int student_home_1_3_chose;
	scanf("%d",&student_home_1_3_chose);

	getchar();
	flag_student_home_1_3_chose=0;
	switch (student_home_1_3_chose)
	{
	    case 1:student_look_teacher_info(head_teacher,head_student);break;
	    case 2:student_look_student_info(head_teacher,head_student);break;
	    case 3:student_home(&head_teacher,&head_student);break;
	    default :flag_student_home_1_3_chose=1;
		     printf("\t\t\t选择错误，请重新输入!\n");
	}
    }
}


void student_home(T_LINK **head_teacher,S_LINK **head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             学生主界面               *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择：1.修改个人信息                  \n");
    printf("\t\t\t                      2.查看帐户信息                  \n");
    printf("\t\t\t                      3.退出登录                      \n");

    int flag_student_home_1_chose=1;
    while(flag_student_home_1_chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");
	int student_home_1_chose;
	scanf("%d",&student_home_1_chose);

	getchar();
	flag_student_home_1_chose=0;
	switch (student_home_1_chose)
	{
	    case 1:manage_my_info(head_teacher,head_student);break;
	    case 2:student_look_user_info(*head_teacher,*head_student);break;
	    case 3:free_teacher_link(head_teacher);
		   free_student_link(head_student);
		   student_logout();break;
	    default :flag_student_home_1_chose=1;
		     printf("\t\t\t选择错误，请重新输入!\n");
	}
    }
}

//登录函数  
void student_login(T_LINK**head_teacher,S_LINK **head_student)
{
    printf("\n\n\t\t\t\t>>>>>>>>>学生登录<<<<<<<<<\n");
    static int flag_enter_user_error_count=0;//输入错误次数统计，大于10次退出
    printf("\t\t\t用户名:");
    scanf("%s",user_name);
    printf("\t\t\t密  码:");
    scanf("%s",pass_word);


    S_LINK *p;
    p=(*head_student)->next;
    while(p)
    {
	if(0==strcmp(user_name,p->name)&&0==strcmp(pass_word,p->pass_word))//匹配成功进入
	{
	    flag_enter_user_error_count=0;//输入错误次数清0
	    student_login_success();//显示登录成功界面
	    student_home(head_teacher,head_student);//进入管理员功能
	    return ;
	}
	p=p->next;
    }
    if(p==NULL)
    {
	flag_enter_user_error_count++;//输入错误次数＋1
	printf("\t\t\t\t验证失败了！\n");
	printf("\t\t\t\t第  %d 次失败 !\n",flag_enter_user_error_count);


	if(flag_enter_user_error_count>2)//输入错误大于10，退出登录
	{
	    flag_enter_user_error_count=0;//输入错误次数清0
	    printf("\n\n\n\t\t\t>>>>>>>>为何久久都输入不对呢？不给你输入了<<<<<<<<<<");
	    printf("\n\n");
	    printf("\n\n");
	    sleep(2);
	    exit_system(head_teacher,head_student);

	}
	else	
	{
	    printf("\t\t\t\t验证失败了，请重新输入!\n");
	    student_login(head_teacher,head_student);
	}
    }
}

void student_login_success()
{
    system("clear");
    printf("\n\t\t\t******************************************************\t\t\t\n");
    printf("\t\t\t***************  TT TT           TT TT     ***********\t\t\t\n");
    printf("\t\t\t**************   IIXII           IIXII      **********\t\t\t\n");
    printf("\t\t\t************     II II           II II       *********\t\t\t\n");
    printf("\t\t\t************                                 *********\t\t\t\n");
    printf("\t\t\t************           用户登录成功          *********\t\t\t\n");
    printf("\t\t\t************                                 *********\t\t\t\n");
    printf("\t\t\t*************            欢迎使用           **********\t\t\t\n");
    printf("\t\t\t**************                             ***********\t\t\t\n");
    printf("\t\t\t*****************                        *************\t\t\t\n");
    printf("\t\t\t******************************************************\t\t\t\n");
    getchar();
    getchar();
}
void student_logout()
{
    system("clear");
    printf("\n\t\t\t*****************************************************\t\t\t\n");
    printf("\t\t\t***************  x x            x x       ***********\t\t\t\n");
    printf("\t\t\t**************    x              x         **********\t\t\t\n");
    printf("\t\t\t************     x x            x x         *********\t\t\t\n");
    printf("\t\t\t************                                *********\t\t\t\n");
    printf("\t\t\t************          退出登录成功          *********\t\t\t\n");
    printf("\t\t\t************                                *********\t\t\t\n");
    printf("\t\t\t*************           再    见           **********\t\t\t\n");
    printf("\t\t\t**************                            ***********\t\t\t\n");
    printf("\t\t\t*****************                       *************\t\t\t\n");
    printf("\t\t\t*****************************************************\t\t\t\n");
    getchar();
    getchar();
    system("clear");
    welcome();
    welcome_chose_enter_login();
}
